package cn.itsource.system.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.system.domain.TSystemdictionarytype;
import cn.itsource.system.query.TSystemdictionarytypeQuery;
import cn.itsource.system.service.TSystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@Validated
@RequestMapping("/tSystemdictionarytype")

public class TSystemdictionarytypeController {
    @Autowired
    private TSystemdictionarytypeService tSystemdictionarytypeService;


    @PutMapping("/save")
    public AjaxResult save(@RequestBody @Validated TSystemdictionarytype tSystemdictionarytype){
        System.out.println(tSystemdictionarytype);
        try {
            tSystemdictionarytypeService.save(tSystemdictionarytype);
            return new AjaxResult().setSuccess(true).setMessage("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("保存失败");
        }
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            tSystemdictionarytypeService.delete(id);
            return new AjaxResult().setSuccess(true).setMessage("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("删除失败");
        }
    }

    @PatchMapping("/patchDelete")
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            tSystemdictionarytypeService.patchDelete(ids);
            return new AjaxResult().setSuccess(true).setMessage("批量删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("批量删除失败");
        }
    }

    @GetMapping("/selectAll")
    public AjaxResult selectAll(){
        try {
            List<TSystemdictionarytype> tMenus = tSystemdictionarytypeService.selectAll();
            return new AjaxResult().setSuccess(true).setResultObj(tMenus);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false);
        }
    }

    @PostMapping("/selectByQueryPage")
    public AjaxResult selectByPage(@RequestBody TSystemdictionarytypeQuery tSystemdictionarytypeQuery)
    {
        try {
            return new AjaxResult().me().setResultObj(tSystemdictionarytypeService.selectByQueryPage(tSystemdictionarytypeQuery));
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("服务器异常");
        }
    }
}
